package com.dzsw.javabase.clazz;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collection;

public class InstanceDemo {

    public static void main(String[] args) {
        Object person = new Person("Jack", 40);
        Object stu = new Student("Rose", 24, "6班", "3年");
        // 1. instanceof
        System.out.println("person instanceof Person >> " + (person instanceof Person));
        System.out.println("stu instanceof Person >> " + (stu instanceof Person));
        System.out.println("person instanceof Student >> " + (person instanceof Student));
        System.out.println("stu instanceof Student >> " + (stu instanceof Student));
        // 2. Class.isInstance()
        System.out.println("Person.class.isInstance(person) >> " + Person.class.isInstance(person));
        System.out.println("Person.class.isInstance(stu) >> " + Person.class.isInstance(stu));
        System.out.println("Student.class.isInstance(person) >> " + Student.class.isInstance(person));
        System.out.println("Student.class.isInstance(stu) >> " + Student.class.isInstance(stu));
        // 3. Class.isAssignableFrom()
        System.out.println("Person.class.isAssignableFrom(person.getClass()) >> " + Person.class.isAssignableFrom(person.getClass()));
        System.out.println("Person.class.isAssignableFrom(stu.getClass()) >> " + Person.class.isAssignableFrom(stu.getClass()));
        System.out.println("Student.class.isAssignableFrom(person.getClass()) >> " + Student.class.isAssignableFrom(person.getClass()));
        System.out.println("Student.class.isAssignableFrom(stu.getClass()) >> " + Student.class.isAssignableFrom(stu.getClass()));
    }


    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Person extends ArrayList {

        private String name;

        private int age;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Student extends ArrayList {

        private String name;

        private int age;

        private String className;

        private String grade;
    }
}
